package com.pyh.libray.log;

import android.util.Log;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PLogManager {

    private PLogConfig pLogConfig;
    private static volatile PLogManager pLogManager;
    private List<PLogPrinter> printers = new ArrayList<>();

    private PLogManager(@NonNull PLogConfig config, PLogPrinter[] printers) {
        this.pLogConfig = config;
        if (printers != null) {
            this.printers.addAll(Arrays.asList(printers));
        }
    }

    public static void init(PLogConfig config, PLogPrinter[] printers) {
        pLogManager = new PLogManager(config, printers);
    }

    public static PLogManager getInstance() {
        if (pLogManager == null) {
            synchronized (PLogManager.class) {
                if (pLogManager == null) {
                    Log.e("PLog", "pLogManager automatic init");
                    pLogManager = new PLogManager(defaultPLogConfig(), null);
                }
            }
        }
        return pLogManager;
    }

    private static PLogConfig defaultPLogConfig() {
        return null;
    }

    public PLogConfig getpLogConfig() {
        return pLogConfig;
    }

    public List<PLogPrinter> getPrinters() {
        return printers;
    }

    public void addPrinter(PLogPrinter printer) {
        printers.add(printer);
    }

    public void removePrinter(PLogPrinter printer) {
        printers.remove(printer);
    }
}
